import java.util.LinkedList;
import java.util.List;

public class MyQueue {

    public static class ListNode{
        ListNode next;
        ListNode prev;
        int val;

        public ListNode(int val){
            this.val = val;
        }
    }

    ListNode first;
    ListNode last;

    int size;

    //进入队列
    public void offer(int val){
        ListNode node = new ListNode(val);
        //1.首次进入
        if(first == null){
            first = node;
        }else{
            last.next = node;
            node.prev = last;
        }
        last = node;
        size++;
    }
    //退出队列:将头元素退出
    public int poll(){
        int val = 0;
        //1.没有元素
        if(isEmpty()) return -1;
        //2。只有一个元素
        if(first.next == null){
            val = first.val;
            first = null;
            last = null;
        }else{
            val = first.val;
            first.next.prev = null;
            first = first.next;
            first.next = null;
        }
        size--;
        return val;
    }

    //获取队列头元素
    public int peek(){
        if(first == null){
            return -1;
        }
        return first.val;
    }

    //获取大小
    public int size(){
        return size;
    }
    //判断是否为空
    public boolean isEmpty(){
        return first == null;
    }
}
